<?php

/*------------------------------------------------
*
*   Explay Engine Content Management System.
*   Copyright © 2008 Golovdinov Alexander.
*
*-------------------------------------------------
*
*   Official site: wwww.alex-home.spb.ru/explay.html
*   Contact e-mail: golovdinov@gmail.com
*
*   GNU General Public License original source:
*   http://www.gnu.org/licenses/gpl-3.0.html
*
------------------------------------------------*/

if (!defined ('EXPLAY')) exit;

include $_SERVER['DOCUMENT_ROOT'].'/modules/articles/interfaces.php';
include $_SERVER['DOCUMENT_ROOT'].'/modules/articles/controller.class.php';

	
$oArticles = articlesController::getInstance();
articlesController::$main_url = '/my_articles/';

$oArticles->load_class ($_SERVER['DOCUMENT_ROOT'].'/modules/articles/user_model.class.php', 'userModelArticles');

include $_SERVER['DOCUMENT_ROOT'].'/modules/articles/mysql.class.php';
include $_SERVER['DOCUMENT_ROOT'].'/modules/articles/user_view.class.php';
include $_SERVER['DOCUMENT_ROOT'].'/modules/articles/view.class.php';

if (my_karma() >= $oArticles->settings['new_blog_karma']) { 
	
	past_navblock (array (
		array ('Мои статьи', '/my_articles/', 'name', 'my_articles', 'cat', 'add'),
		array ('Написать статью', '/my_articles/add/', 'cat', 'add'),
		array ('Создать новый блог', '/my_articles/new_blog/', 'cat', 'new_blog')
	));
	
} else {
	past_navblock (array (array ('Написать статью', '/my_articles/add/', 'cat', 'add')));
}

$oArticles->load_settings ();

// Удаление статьи
if (isset($_GET['delete'])) {
	$oArticles->add_filter ('art_id', intval ($_GET['delete']));
	$oArticles->delete_article ();
	
	$oArticles->clear_filters ();
}

// Сохранение статьи
if (isset($_GET['save'])) {
	$oArticles->save_article ();	
}

// Сохранение блога
if (isset($_GET['save_blog'])) {
	$oArticles->save_blog ();
}

// Форма редактирования статьи
if (isset($_GET['edit']) && isset ($_GET['id'])) {
	$oArticles->add_filter ('art_id', intval ($_GET['id']));
	if (!is_moderator ())$oArticles->add_filter ('art_author', User::$properties['user_id']);
	
	$oArticles->edit_article ();
}

// Форма редактирования блога
elseif (isset($_GET['edit_blog'])) {
	$oArticles->add_filter ('cat_id', intval ($_GET['edit_blog']));
	$oArticles->edit_blog ();
}

// Форма новой статьи
elseif (isset($_GET['cat']) && $_GET['cat'] == "add") {
	$oArticles->add_article ();
}

// Форма нового блога
elseif (isset($_GET['cat']) && $_GET['cat'] == "new_blog") {
	$oArticles->add_blog ();

// Вывод списка статей
} else {
	$user_view = new userViewArticles;
	$blogs = $user_view->blog_bar();
	if ($blogs) print $blogs;
	unset ($user_view);
	
	$oArticles->load_class ($_SERVER['DOCUMENT_ROOT'].'/modules/articles/model.class.php', 'articlesModel');
	$oArticles->init_page ();
		
	$oArticles->add_filter ('art_author', User::$properties['user_id']);
	$oArticles->set_author (User::$properties['user_id']);
	$oArticles->set_bar_off ();
	$oArticles->past_articles_list ();

}

$oArticles->show_result ();